﻿using RIDA.Globals;
using System.Collections.ObjectModel;
using System.Windows;
using RIDA.Globals.Interfaces;
using RIDA.DiagramDesigner.ViewModel;
namespace RIDA.DiagramDesigner
{

    public class DiagramDesignerViewModel : ViewModelBase,IDiagramDesignerViewModel
    {
        

        public DiagramDesignerViewModel()
        {
            
        }

        #region Properties

        private ObservableCollection<IDiagramElementViewModel> _items;

        public ObservableCollection<IDiagramElementViewModel> Items
        {
            get
            {
                if (_items == null)
                    _items = new ObservableCollection<IDiagramElementViewModel>();
                return _items;
            }
        }


        #endregion

        public void AddDesignerItem(ViewModelBase viewModel)
        {
            //TODO: check if it exists before
            Items.Add(new DesignerItemViewModel()
            {
                Content = viewModel
            });
        }

        public void AddConnectionItem(IDiagramElementViewModel viewModel)
        {
            Items.Add(viewModel);
        }
         /// <summary>
         /// 
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>

        public void OnDrop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(DataFormats.StringFormat))
                return;

            var designerItemViewModel = e.Data.GetData(DataFormats.StringFormat) as DesignerItemViewModel;
            if (designerItemViewModel == null)
                return;

            var position = e.GetPosition(sender as UIElement);
            designerItemViewModel.IsHitVisible = false;//to see the cross cursor on the drag thumb region
            var item = new DesignerItemViewModel()
            {
                Left = position.X,
                Top = position.Y,
                IsHitVisible = false,
                Content = designerItemViewModel

            };
            Items.Add(item);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnDragEnter(object sender, DragEventArgs e)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnDragLeave(object sender, DragEventArgs e)
        {

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnDragOver(object sender, DragEventArgs e)
        {

        }

        
    }
}
